package cn.ainit.fx.hkjh;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

@Service
public class FxhkjhService {
	private FxhkjhDao fxhkjhDao;

	@Resource
	public void setFxhkjhDao(FxhkjhDao fxhkjhDao) {
		this.fxhkjhDao = fxhkjhDao;
	}

	public HKJHParam addHkjhMain(HKJHParam hp) {
		String msg=fxhkjhDao.ProJdbcExec(hp);
		if(msg.equals("0")){
			hp.setMessage("本月已经添加过不可重复");
		}else {
			hp.setHkpId(msg);
		}
		return hp;
		
	}
    /**
     * 
     * @Title: addhkjhDetailClientService
     * @author : FuXiangYi  
     * @Description: 添加hkjh明细客户信息
     * @param hp
     * @return    
     * @return HKJHParam 
     * @date 2014-12-8 下午04:51:46
     */
	public HKJHParam addhkjhDetailClientService(HKJHParam hp) {
		
		//判断时候已经添加过
		String querySql ="select * from fx_clients_hkplan_item where hkp_id='"+hp.getHkpId()+"'";
		List<Map<String, Object>> listmap=fxhkjhDao.querJDBCBySql(querySql);
		if(listmap.size()<=0){
			
			//查询出所有的客户信息
			String clientSql="select * from bs_clients b where b.o_id_lastgr ='"+hp.getSalesman()+"' and IS_EXIST='1' ";
			List<Map<String, Object>> list=fxhkjhDao.querJDBCBySql(clientSql);
			//添加的sql
			String updateSql =null;
			for(Map<String, Object> map :list){
				updateSql="insert into fx_clients_hkplan_item(hkp_id,client_id) values('"+hp.getHkpId()+"','"+map.get("CLIENTS_ID")+"')";
	            fxhkjhDao.getJDBCUpdateBySql(updateSql);
			}
		}
		
		
		return null;
	}

}
